from openpyxl import load_workbook
import os

filename = os.getcwd() + os.sep + 'test.xlsx'
workbook = load_workbook(filename)
print(workbook.sheetnames)
#根究名称获取工作表
sheet = workbook['Sheet1']
#如果只有一张工作表可以用
sheet1 = workbook.active
print(sheet1.dimensions)

#获取某个单元格
#方法1：指定坐标
cell = sheet1['A1']
print(cell.value)
#方法2：通过行和列
cell1 = sheet1.cell(2,2)
print(cell1.value)
#获取某个单元格的行、列、坐标
print(cell1.row,cell1.column,cell1.coordinate)

#获取多个格子的值
cells = sheet1[2]
for cell in cells:
    print(cell.value)

#读取所有的行
for row in sheet1.rows:
    print(row)

